 

 function check(option) {

	var errtxt = '',
		len;
	 option = option||{};
	 

	this.verify = function(obj){
			errtxt = '';
			for (let i in obj) {
				 	 
				if (option[i]) {
					len = trim(obj[i]).length;
					if (option[i].required && len == 0) {
						errtxt = option[i].required;
					} else if (option[i].minlength && len < option[i].minlength) {
						errtxt = option[i].minError;
					} else if (option[i].maxlength && len > option[i].maxlength) {
						
						errtxt = option[i].maxError;
						
					} else if (option[i].isPhone &&  checkisMobile(obj[i])) {
						errtxt = option[i].isPhone;
						
					} else if (option[i].strength &&  checkStrength(obj[i])) {
						errtxt = option[i].strength;
					}
					//如果存在错误信息直接提示错误信息
					if (errtxt) {
						  
						//弹窗报错
//						 console.log(errtxt);
						 
						return false;
					}
				}
			}
		return true;
	}
	 

}
function trim(s) {
	return trimRight(trimLeft(s));
}
function trimLeft(s) {
	if (s == null) {
		return "";
	}
	var whitespace = new String(" \t\n\r");
	var str = new String(s);
	if (whitespace.indexOf(str.charAt(0)) != -1) {
		var j = 0, i = str.length;
		while (j < i && whitespace.indexOf(str.charAt(j)) != -1) {
			j++;
		}
		str = str.substring(j, i);
	}
	return str;
}
function trimRight(s) {
	if (s == null) return "";
	var whitespace = new String(" \t\n\r");
	var str = new String(s);
	if (whitespace.indexOf(str.charAt(str.length - 1)) != -1) {
		var i = str.length - 1;
		while (i >= 0 && whitespace.indexOf(str.charAt(i)) != -1) {
			i--;
		}
		str = str.substring(0, i + 1);
	}
	return str;
}
 
 function checkStrength(password) {
  
 	if(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{6,20}$/.test(password)){
 		
 		return false;
 	}  
 	
    return true;
 	
 }
 function checkisMobile(mobile) {
 	
 	if(/^0?(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])[0-9]{8}$/.test(mobile)){
 		
 		return false;
 	}  
 	
    return true;
 	
 }
 
export default {
	check
}
